<template>
  <f-page-layout title="护理记录表单" :actions="actions">
    <f-dy-print
      ref="printer"
      :columns="config.config.columns"
      :data="nursingData"
      :tableBeforeContent="beforeContent"
      :tableAfterContent="afterContent"
      :renderCell="renderBodyCell"
      direction="landscape"
      mainTitle="西藏阜康医院"
      title="住院一般护理记录">
    </f-dy-print>
  </f-page-layout>
</template>
<script setup lang="ts">
import { xml2json } from 'fok-js';
import { computed, reactive, ref } from 'vue';
import { printNursingTable } from '../../packages';
import {
  getDisplayData,
  renderCell
} from '../../packages/components/dyTemplate/src/impls/nursing/common';
const printer = ref();

const renderBodyCell = ({ row, columnIndex: index, column }) => {
  return renderCell({ row, index, column, cellClass: 'p8', cellValue: row[column.field] });
};
const actions = [
  {
    label: '新增护理记录',
    type: 'primary',
    icon: 'el-icon-document-copy',
    click: () => {}
  },
  {
    label: '打印',
    type: 'primary',
    icon: 'el-icon-document-copy',
    click: () => {
      // 预览打印
      printer.value.print();
      // 函数直接打印
      // printNursingTable({
      //   columns: config.config.columns,
      //   data: remoteData,
      //   mainTitle: '西藏阜康医院',
      //   title: '住院-一般护理记录-直接打印',
      //   direction: 'landscape',
      //   tableBeforeContent: beforeContent,
      //   tableAfterContent: afterContent,
      //   renderCell: renderBodyCell as any
      // });
    }
  }
];
const beforeContent = `
<img style="height:50px;position:absolute;right:1cm;top:1cm;" src="http://172.16.88.7:81/his-main/assets/logo-lt-3db7e9bd.1743229615275.png"/>
<div style="display:flex;justify-content:space-between;padding:8px 0;font-size:12px;">
  <div>姓名:李四</div>
  <div>科室:住院1楼</div>
  <div>床号:1001</div>
  <div>诊断:感冒流鼻涕</div>
  <div>时间:2023-11-11</div>
  <div>住院号：1110012</div>
</div>`;
const afterContent = `<div style="padding-top:12px;font-size:12px;">建议：患者因"咳嗽,咳痰10余年,加重伴喘憋7天"门诊以"慢性阻塞性肺疾病"收入院.入院后医嘱病重,给予持续低流量氧气吸入,持续心电监护,行人科介绍</div>`;
// 使用示例
// 约定的数据格式,提交和返回都使用该格式进行解析
let remoteData: any[] = new Array(30).fill(null).map((item, i) => ({
  isMerge: i % 6 === 0,
  id: Math.random().toString().slice(2),
  info: '我说的飞机螺丝钉解放拉萨的飞机数量大幅',
  values: {
    collectDatetime: { type: '1', text: i + 1 },
    '120250300000938': { type: '2', dict: null },
    '120250300000957': {
      type: '4',
      object: {
        '120250300000955': { type: '1', text: '23' },
        '120250300000956': { type: '1', text: '123' }
      }
    },
    '120250300000940': { type: '1', text: '213' },
    '120250300000939': { type: '1', text: '123' },
    '120250300000950': {
      type: '4',
      object: {
        '120250300000941': { type: '1', text: '123' },
        '120250300000942': { type: '1', text: '213' }
      }
    },
    '120250300000943': { type: '1', text: '123' },
    '120250300000961': {
      type: '4',
      object: {
        '120250300000954': { type: '1', text: 123 },
        '120250300000960': { type: '2', dict: { code: '1', desc: '正菜鸡' } },
        '120250300000958': { type: '1', text: '123' },
        '120250300000959': { type: '2', dict: { code: '1', desc: '辅材' } }
      }
    },
    '120250300000953': {
      type: '3',
      list: [
        {
          '120250300000944': { type: '1', text: '1' },
          '120250300000945': { type: '1', text: '2' }
        },
        {
          '120250300000944': { type: '1', text: '3' },
          '120250300000945': { type: '1', text: '4' }
        }
      ]
    },
    '120250300000952': {
      type: '3',
      list: [
        {
          '120250300000946': { type: '1', text: '234' },
          '120250300000947': { type: '1', text: '324' },
          '120250300000948': { type: '1', text: '234' }
        }
      ]
    },
    '120250300000949': {
      type: '1',
      text: '东方巨龙束带结发螺蛳粉较大是打发立卡,东方巨龙束带结发,很简单开发撒谎洞口防护手打'.slice(
        0,
        Math.floor(Math.random() * 20)
      )
    },
    sign: { type: '1', text: null }
  }
}));
const nursingData = computed(() => {
  return getDisplayData(remoteData, config.config.columns);
});
const xmlStr = `<application xmlns="http://www.w3.org/1999/xhtml">
  <type type="string">table</type>
  <config type="object">
    <top-form type="array"></top-form>
    <columns type="array">
      <array-item type="object">
        <title type="string">记录日期</title>
        <field type="string">collectDatetime</field>
        <edit-type type="string">date</edit-type>
        <min-width type="number">150</min-width>
        <props type="object">
          <format type="string">YYYY-MM-DD HH:mm</format>
          <value-format type="string">YYYY-MM-DD HH:mm</value-format>
          <show-time type="boolean">true</show-time>
        </props>
      </array-item>
      <array-item type="object">
        <title type="string">意识</title>
        <field type="string">120250300000938</field>
        <edit-type type="string">dictionary</edit-type>
        <min-width type="number">120</min-width>
        <props type="object">
          <code type="string">EAC_YS</code>
        </props>
      </array-item>
      <array-item type="">
        <title type="string">氧疗(L/min)</title>
        <field type="string">120250300000957</field>
        <data-type type="string">column-object</data-type>
        <children type="array">
          <array-item type="object">
            <title type="string">鼻导管</title>
            <field type="string">120250300000955</field>
            <edit-type type="string">input</edit-type>
            <min-width type="number">150</min-width>
          </array-item>
          <array-item type="object">
            <title type="string">面罩</title>
            <field type="string">120250300000956</field>
            <edit-type type="string">input</edit-type>
            <min-width type="number">150</min-width>
          </array-item>
        </children>
      </array-item>

      <array-item type="object">
        <title type="string">呼吸（次/min）</title>
        <field type="string">120250300000940</field>
        <edit-type type="string">input</edit-type>
        <min-width type="number">150</min-width>
      </array-item>
      <array-item type="object">
        <title type="string">心率（次/min）</title>
        <field type="string">120250300000939</field>
        <edit-type type="string">input</edit-type>
        <min-width type="number">120</min-width>
      </array-item>
      <array-item type="object">
        <title type="string">血压(mmHg)</title>
        <children type="array">
          <array-item type="object">
            <title type="string">收缩压/舒张压</title>
            <field type="string">120250300000950</field>
            <align type="string">center</align>
            <edit-type type="string">dy-inputs</edit-type>
            <data-type type="string">object</data-type>
            <min-width type="number">150</min-width>
            <props type="object">
              <fields type="array">
                <array-item type="object">
                  <field type="string">120250300000941</field>
                  <edit-type type="string">input</edit-type>
                </array-item>
                <array-item type="object">
                  <field type="string">120250300000942</field>
                  <edit-type type="string">input</edit-type>
                </array-item>
              </fields>
            </props>
          </array-item>
        </children>
      </array-item>
      <array-item type="object">
        <title type="string">血氧饱和度(%)</title>
        <field type="string">120250300000943</field>
        <edit-type type="string">input</edit-type>
        <min-width type="number">120</min-width>
      </array-item>
      <array-item type="object">
        <title type="string">体温</title>
        <field type="string">120250300000961</field>
        <data-type type="string">column-object</data-type>
        <children type="array">
          <array-item type="object">
            <title type="string">数值℃</title>
            <field type="string">120250300000954</field>
            <edit-type type="string">input-number</edit-type>
            <min-width type="number">80</min-width>
          </array-item>
          <array-item type="object">
            <title type="string">类型</title>
            <field type="string">120250300000960</field>
            <edit-type type="string">dictionary</edit-type>
            <min-width type="number">80</min-width>
            <props type="object">
              <code type="string">ENR_CollectionTypeEnum</code>
            </props>
          </array-item>
          <array-item type="object">
            <title type="string">拒测原因</title>
            <field type="string">120250300000958</field>
            <edit-type type="string">input</edit-type>
            <min-width type="number">150</min-width>
          </array-item>
          <array-item type="object">
            <title type="string">降温措施</title>
            <field type="string">120250300000959</field>
            <edit-type type="string">dictionary</edit-type>
            <min-width type="number">100</min-width>
            <props type="object">
              <code type="string">ENR_TMeasureEnum</code>
            </props>
          </array-item>
        </children>
      </array-item>
      <array-item type="object">
        <title type="string">入量</title>
        <field type="string">120250300000953</field>
        <data-type type="string">array</data-type>
        <children type="array">
          <array-item type="object">
            <title type="string">入量名称</title>
            <field type="string">120250300000944</field>
            <edit-type type="string">dy-array</edit-type>
            <min-width type="number">150</min-width>
            <props type="object">
              <type type="string">input</type>
            </props>
          </array-item>
          <array-item type="object">
            <title type="string">ml</title>
            <field type="string">120250300000945</field>
            <edit-type type="string">dy-array</edit-type>
            <min-width type="number">80</min-width>
            <props type="object">
              <type type="string">input</type>
            </props>
          </array-item>
          <array-item type="object">
            <edit-type type="string">dy-operates</edit-type>
            <field type="string">col93</field>
            <data-type type="string">none</data-type>
            <min-width type="number">100</min-width>
            <props type="object">
              <fields type="array">
                <array-item type="string">120250300000944</array-item>
                <array-item type="string">120250300000945</array-item>
              </fields>
            </props>
          </array-item>
        </children>
      </array-item>
      <array-item type="object">
        <title type="string">出量</title>
        <field type="string">120250300000952</field>
        <data-type type="string">array</data-type>
        <children type="array">
          <array-item type="object">
            <title type="string">名称</title>
            <field type="string">120250300000946</field>
            <edit-type type="string">dy-array</edit-type>
            <min-width type="number">150</min-width>
            <props type="object">
              <type type="string">input</type>
            </props>
          </array-item>
          <array-item type="object">
            <title type="string">ml</title>
            <field type="string">120250300000947</field>
            <edit-type type="string">dy-array</edit-type>
            <min-width type="number">80</min-width>
            <props type="object">
              <type type="string">input</type>
            </props>
          </array-item>
          <array-item type="object">
            <title type="string">性状</title>
            <field type="string">120250300000948</field>
            <edit-type type="string">dy-array</edit-type>
            <min-width type="number">80</min-width>
            <props type="object">
              <type type="string">input</type>
            </props>
          </array-item>
          <array-item type="object">
            <edit-type type="string">dy-operates</edit-type>
            <field type="string">col94</field>
            <data-type type="string">none</data-type>
            <min-width type="number">100</min-width>
            <props type="object">
              <fields type="array">
                <array-item type="string">120250300000946</array-item>
                <array-item type="string">120250300000947</array-item>
                <array-item type="string">120250300000948</array-item>
              </fields>
            </props>
          </array-item>
        </children>
      </array-item>
      <array-item type="object">
        <title type="string">病情观察及护理措施</title>
        <field type="string">120250300000949</field>
        <edit-type type="string">input-textArea</edit-type>
        <min-width type="number">200</min-width>
      </array-item>
      <array-item type="object">
        <title type="string">护士签名</title>
        <field type="string">sign</field>
        <edit-type type="string">dy-sign</edit-type>
        <min-width type="number">100</min-width>
      </array-item>
    </columns>
  </config>
  <create-time type="string">2025-03-26 14:33:48</create-time>
  <title type="string"></title>
  <main-title type="string"></main-title>
</application>
`;
const config = reactive(xml2json(xmlStr));
</script>
